# Maintainer: Patrycja Rosa <alpine@ptrcnull.me>
pkgname=nvtop
pkgver=3.0.2
pkgrel=0
pkgdesc="GPUs process monitoring for AMD, Intel and NVIDIA"
url="https://github.com/Syllo/nvtop"
# no gpus that are usable on s390x
arch="all !s390x"
license="GPL-3.0-or-later"
makedepends="
	cmake
	eudev-dev
	libdrm-dev
	ncurses-dev
	samurai
	"
subpackages="$pkgname-doc"
source="https://github.com/Syllo/nvtop/archive/$pkgver/nvtop-$pkgver.tar.gz"
options="!check" # no tests provided by upstream

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		local crossopts="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi

	case "$CARCH" in
	arm*|aarch64) local msm=ON ;;
	*) local msm=OFF ;;
	esac

	CFLAGS="$CFLAGS -flto=auto -DNDEBUG" \
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=None \
		-DAMDGPU_SUPPORT=ON \
		-DINTEL_SUPPORT=ON \
		-DMSM_SUPPORT=$msm \
		-DNVIDIA_SUPPORT=ON \
		$crossopts
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
e5f23796c37b21f9e16f90b6aecce010239f736e60698fec22f663afef24439680132cb4bf08c56b9c05a9a69fa81421fed46c392adc06435f5209552337caed  nvtop-3.0.2.tar.gz
"
